<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/10/0010
 * Time: 11:19
 */

namespace app\sports_admin\controller;

use app\sports_admin\model\DissertationType as DissertationTypeModel;
use app\sports_admin\service\DissertationType as DissertationTypeService;
use think\Request;

class DissertationType extends Base
{
    protected $beforeActionList = [
        'isResource'=>['only'=>'index,add,insertchildren,parent,insertparent,edit,update,deletetypeinfo'],
        'operationSelect'=>['only'=>'index,add,parent'],
        'operationInsert'=>['only'=>'insertchildren,insertparent'],
        'operationUpdate'=>['only'=>'update'],
        'operationDelete'=>['only'=>'deletetypeinfo']
    ];
    /*
     * 论文指导类别首页
     * @param $data 类别信息
     */
    public function index()
    {
        $data = DissertationTypeModel::getDissertationTypeList();
        return view('index',compact('data'));
    }
    /*
     * 添加子类
     */
    public function add()
    {
        //pid 父类id  title父类名称  path 路径
        $data = Request::instance()->only(['pid','title','path']);
        return view('add',compact('data'));
    }
    /*
     * 添加子类信息
     */
    public function insertChildren(Request $request)
    {
        if($request->isAjax()){
            return DissertationTypeService::insertChildren();
        }
    }
    /*
     * 添加父类页面
     */
    public function parent()
    {
        return view('parent');
    }
    /*
     * 添加父类信息
     */
    public function insertParent(Request $request)
    {
        if($request->isAjax()){
            return DissertationTypeService::insertParent();
        }
    }
    /*
     * 编辑
     * @param $id 类别id
     */
    public function edit()
    {
        $id = input('get.id');
        $data = DissertationTypeModel::findTypeInfo($id);
        return view('edit',compact('data'));
    }
    /*
     * 修改
     */
    public function update(Request $request)
    {
        if($request->isAjax()){
            return DissertationTypeService::update();
        }
    }
    /*
     * 删除类别信息
     */
    public function deleteTypeInfo(Request $request)
    {
        if($request->isAjax()){
            return DissertationTypeService::deleteTypeInfo();
        }
    }
}